#include <cassert>
#include <stdio.h>

template<class T>
class simpleStack {

public:
	static const unsigned int MAX_SIZE = 20;
	simpleStack() :
		anzahl(0) {
		s = new T[MAX_SIZE];
	}
	void push(T);
	T pop();
	T top();

private:
	unsigned int anzahl;
	T *s;
};

// ==> Implementierung von simpleStack
template<class T> void simpleStack<T>::push(T element) {
	if (anzahl == MAX_SIZE) {
		printf("Stack overflow!");
		return;
	}
	anzahl++;
	s[anzahl - 1] = element;
}
template<class T> T simpleStack<T>::pop() {
	if (anzahl == 0) {
		printf("Stack underflow!");
		return NULL;
	}
	anzahl--;
	return s[anzahl];
}
template<class T> T simpleStack<T>::top() {
	if (anzahl == 0) {
		printf("Stack empty!");
		return NULL;
	}
	return s[anzahl - 1];
}
// <==


class Element {
public:
	int value;
	Element(int val) {
		value = val;
	}
	Element() {
	}
	void printMe() const {
		printf("%d\n", value);
	}
};

class Test {
public:
	static void myMain() {
		simpleStack<Element> * myStack = new simpleStack<Element> ();
		myStack->push(*new Element(5));
		myStack->push(*new Element(7));
		myStack->push(*new Element(9));
		myStack->top().printMe();
		myStack->pop();
		myStack->top().printMe();
	}
};

int main(int argc, char ** argv) {
	Test::myMain();
}
